import React, { Component } from 'react'
import qs from "qs"
import { goodsRequest } from '../../request/cate_request'
import Header from "./component/DefaultHeader"
export default class GoodsList extends Component {
    state = {
        title: "",
        goods_list: []
    }
    UNSAFE_componentWillMount() {
        let { type_id, type_name } = qs.parse(this.props.location.search.substring(1))
        goodsRequest(type_id).then(res => {
            this.setState({ goods_list: res.list })
        })
        this.setState({ title: type_name })
    }
    render() {
        const { title, goods_list } = this.state
        const {history}=this.props
        return (
            <div>
                <Header title={title}/>
                {
                    goods_list.map(item => (
                        <div className="goodslist" key={item.id}>
                            <div className="item">
                                <img src={this.$adress+item.img} alt="" onClick={()=>history.push("/gooddetail/?id="+item.id)} />
                                <div>
                                    <h5 onClick={()=>history.push("/gooddetail/?id="+item.id)}>{item.goodsname}</h5>
                                    <p className="price">&yen;{item.price}</p>
                                    <p className="market-price">&yen;{item.market_price}</p>
                                    <button className="btn-cart">加入购物车</button>
                                </div>
                            </div>
                        </div>
                    ))
                }
            </div>
        )
    }
}
